IF EXISTS (SELECT * from dbo.sysobjects WHERE id = object_id(N'[dbo].[SelectLogServicioByIdInsumo]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[SelectLogServicioByIdInsumo]
GO

CREATE PROCEDURE [dbo].[SelectLogServicioByIdInsumo]
(
	@IdInsumo smallint,
	@FechaAlerta smalldatetime = NULL
)
AS
BEGIN
	SET NOCOUNT ON

	SELECT
	[IdLog],
	[IdTipo],
	[FechaAlerta],
	[IdLote],
	[IdInsumo],
	[Descripcion],
	[FechaCreacion],
	[IdEstado]
	FROM [LogServicio]
	WHERE [IdInsumo] = @IdInsumo AND
	CASE 
		WHEN @FechaAlerta IS NULL THEN 1
		WHEN FechaAlerta = @FechaAlerta THEN 1
		ELSE 0
	END = 1 	

	SET NOCOUNT OFF
END

GO
